<?php

namespace app\admin\controller\datacenter;

use app\common\controller\Backend;

use think\Controller;
use think\Request;
use think\Db;

/**
 * 
 *
 * @icon fa fa-circle-o
 */
class Datacenterx extends Backend
{
    /**
     * 查看
     */
    public function index()
    {
        $seventtime = \fast\Date::unixtime('day', -7);
        $paylist = $createlist = [];

        //7天最高值 这里可以修改为获取数据库中存储的最高7天的在线人数，和开房人数.
        for ($i = 0; $i < 7; $i++)
        {
            $day = date("Y-m-d", $seventtime + ($i * 86400));
            $createlist[$day] = mt_rand(20, 200);
            $paylist[$day] = mt_rand(1, mt_rand(1, $createlist[$day]));
			
        }
		//获取7天的最高在线人数，和最高开房人数,包含时间段.
		
		
        $hooks = config('addons.hooks');

        $totaluser  = $this->selectcount($this->GameDBConfig,'user','');  //注册总人数
        $totalviews = Db::table('fa_v_annal_room')->field('roomid')->where("roomcode > 0")->group('roomid,createtime')->count(); //总开房数
        $totalorder = Db::name('v_annal_room')->where(null)->sum('roomcode'); //总消耗房卡
        $todayuserlogin = $this->selectcount($this->GameDBConfig,'user',"FROM_UNIXTIME(lastLoginTime/1000,'%Y-%m-%d') = date_format(now(),'%Y-%m-%d')");  //今日登陆数
        $todayusersignup = $this->selectcount($this->GameDBConfig,'user',"FROM_UNIXTIME(createTime/1000,'%Y-%m-%d') = date_format(now(),'%Y-%m-%d')");//今日注册数
        $todayorder = Db::name('v_annal_room')->where("FROM_UNIXTIME(createtime/1000,'%Y-%m-%d') = date_format(now(),'%Y-%m-%d')")->sum('roomcode'); //今日房卡消耗
        $unsettleorder = Db::table('fa_v_annal_room')->field('roomid')->where("roomcode > 0 and FROM_UNIXTIME(createTime/1000,'%Y-%m-%d') = date_format(now(),'%Y-%m-%d')")->group('roomid,createtime')->count();//今日开房数
       
        $uploadmode = isset($hooks['upload_config_init']) && $hooks['upload_config_init'] ? implode(',', $hooks['upload_config_init']) : 'local';
        $this->view->assign([
            'totaluser'        => $totaluser,
            'totalviews'       => $totalviews,
            'totalorder'       => $totalorder,
            'totalorderamount' => 0,
            'todayuserlogin'   => $todayuserlogin,
            'todayusersignup'  => $todayusersignup,
            'todayorder'       => $todayorder,
           
			
            
			'unsettleorder'    => $unsettleorder,
            'sevendnu'         => 0, //今日订单量
            'sevendau'         => 0, //今日开房数
            'paylist'          => $paylist, //历史在线在线人数
            'createlist'       => $createlist, //历史最高开房人数
            'uploadmode'       => $uploadmode,//
        ]);

        return $this->view->fetch();
    }

}
